#ifndef ACCEPTOR_H
#define ACCEPTOR_H

#include <memory>
#include <functional>

#include "Socket.h"

class EventLoop;
class Channel;
class InetAddress;

class Acceptor {
public:
    typedef std::function<void(int, InetAddress&)> NewConnectCallback;

    Acceptor(EventLoop* loop, InetAddress& listenAddr);
    ~Acceptor();

    void listen();

    void setNewConnectCallback(const NewConnectCallback& cb) {
        newConnectCallback_ = std::move(cb);
    }


private:
    void handleRead();

    EventLoop* loop_;
    Socket listenSocket_;
    std::unique_ptr<Channel> channel_;
    int idleFd_;


    NewConnectCallback newConnectCallback_;
};

#endif